#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:teacher_controller.py
# author:张世航
# datetime:2024/12/21 01:30
# software: PyCharm
"""
this is function  description 
"""



# controller/teacher_controller.py
from models.teacher import Teacher
from utils.db import Session

def add_teacher(tno, tname, dno, salary, tmobile):
    session = Session()
    new_teacher = Teacher(Tno=tno, Tname=tname, Dno=dno, Salary=salary, Tmobile=tmobile)
    session.add(new_teacher)
    session.commit()
    session.close()

def delete_teacher(tno):
    session = Session()
    teacher = session.query(Teacher).filter(Teacher.Tno == tno).first()
    if teacher:
        session.delete(teacher)
        session.commit()
    session.close()

def query_teacher_by_name(name):
    session = Session()
    teachers = session.query(Teacher).filter(Teacher.Tname == name).all()
    session.close()
    return teachers